clc;
clear all;
close all;
% In the LogDistancePropagationLossModel in ns-3.13, the reference distance
% is 1 meter, the referenceLoss of signal power is 46.6777, the
% transmission power of power level 0 is 16.0206 Dbm, the default threshold
% value of receive power is -96 Dbm.
%
% After running this code, the transmission range is approximately 95.52
% meter when the pass loss exponent is 3.3
%
%
global referenceDistance referenceLoss txPower threshold;
referenceDistance = 1;
referenceLoss =52.1; %46.6777;
%txPower = 17.0206+23;
txPower = -25;
threshold = -89.0630 %-85.0590;
alpha =2.61; %2.6; PathLoss Exponent
watt=realpow(10, (txPower - 30)/10);
mean_background_noise = -98; %dBm.
%rxPower = CalculateRxPower(79.1767, 3.3)

rx_power = CalculateRxPower(400, alpha)
 distance = 0:0.001:200;
 rxPower = CalculateRxPower(distance, alpha);
 plot (distance, rxPower);
 xlabel ('Distance (m)');
 ylabel ('RxPoaer (dBm)');
% 
for dis = distance
    rx_power = CalculateRxPower(dis, alpha);
     if rx_power < (threshold)
         range = dis
         rx_power
         break
     end
end
%rxPower = CalculateRxPower(range*1.5, alpha)
%  The background noise is: -93.996 Dbm
%  The SNR value is 5.65 when the PDR is approximately 80%
%  When the transmission power is 16.0206 and the threshold value of the
%  received poer is -90 Dbm, the transmission range is 62.85 m
